import java.util.Date;


public class RocketAnalysisTool 
{
	private int headerWidth = 42;
	
	/**
	 * @param args
	 */
	public static void main(String[] args) 
	{				
		int headerWidth = 42;
		Project project = null;
		RocketAnalysisTool rat = new RocketAnalysisTool();
		RocketHelper rocketHelper = new RocketHelper(headerWidth);
		
		RocketTools.writeHeader("Rocket Analysis Tool - Iteration 1", "~", "^",42);
		
		System.out.print("Would you like to load an existing project? (Y/N): ");
		String yesNoInput = RocketTools.readInput();
		
		// Create a new project
		if (yesNoInput.equalsIgnoreCase("n") || yesNoInput.equalsIgnoreCase("no"))
		{	
			project = rat.createNewProject();
			
			while (true)
			{			
				int releaseNumber = project.generateReleaseSequenceNum();
				Version version = rocketHelper.newVersion(releaseNumber);
				rocketHelper.analyseVersion(version);
				
				// Add new version
				project.addVersion(version);
				System.out.print("Would you like to add another version to this project? (Y/N): ");
				
				yesNoInput = RocketTools.readInput();
				
				if (yesNoInput.equalsIgnoreCase("n") || yesNoInput.equalsIgnoreCase("no"))
					break;		
			}
		}
		// Load an existing project
		else { project = rocketHelper.load(); }	
				
		System.out.print("Use relative histogram? (Y/N): ");
		
		yesNoInput = RocketTools.readInput();
		
		if (yesNoInput.equalsIgnoreCase("n") || yesNoInput.equalsIgnoreCase("no"))
			rocketHelper.generateChart(project, false);
		else // Generates charts for the specified project
			rocketHelper.generateChart(project, true);
		
		
		// Save using default fileName (the project name)
		rocketHelper.save(project);			
	}	
	

	/**
	 * Allows user to create project using console input. 
	 */
	public Project createNewProject()
	{
		Project project = new Project();
		
		Date startDate = null;
		String projectName = "", projectDescription = "", projectStartDate = "";
		 				
		// Obtain currentProject name from user
		RocketTools.writeHeader("New Project", headerWidth);		
		System.out.print("Enter the Project Name: ");
		projectName = RocketTools.readInput();
		
		// Obtain currentProject start date from user OR use current
		System.out.print("Enter the Start Date DD/MM/YYYY : ");
		projectStartDate = RocketTools.readInput(); //User may or may not enter the start date,it's optional
		startDate = RocketTools.processDate(projectStartDate);		
		
		// Obtain currentProject description (optional)
		System.out.print("Enter the Project Description : ");
		projectDescription = RocketTools.readInput();		
		
		// Set persistent data 
		project.setName(projectName);
		project.setStartDate(startDate);
		project.setDescription(projectDescription);
	
		return project;
	}
}
